﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Jzy.BLL.Mail;
using Jzy.Model.Mail;
using Frame.Lib.Core.User;

namespace Jzy.Web.Mail.Inner
{
    /// <summary>
    /// Summary description for SendReceipt
    /// </summary>
    public class SendReceipt : IHttpHandler
    {

       

        public void ProcessRequest(HttpContext context)
        {
            //context.Response.ContentType = "text/plain";
            //context.Response.Write("Hello World");

            string mailUserID = context.Request.QueryString["MailUserID"];

            int userID = int.Parse(context.Request.QueryString["UserID"]);

            UserBO user = new UserBO();
            UserInfo userInfo = user.GetInfo(userID);

            //MailUserBO mailUser = new MailUserBO();
            //MailUserInfo mailUserInfo = mailUser.GetInfo(mailUserID);

            MailBO mail = new MailBO(userID);
            MailInfo oldMailInfo = mail.GetInfo(mail.GetMailID(mailUserID));
           

            MailInfo info = new MailInfo();
            info.CreatorID = userID;
            if (userInfo == null)
            {
                info.CreatorName = "";
            }
            else
            {
                info.CreatorName = userInfo.Name;
            }
            info.InputTime = DateTime.Now;
            info.Name = "已读：" + oldMailInfo.Name;
            info.Content = "收件人：" + info.CreatorName + "<br/>" +
                            "主题：" + oldMailInfo.Name + "<br/>" +
                            "发送时间：" + oldMailInfo.InputTime + "<br/>" +
                            "阅读时间：" + DateTime.Now;
            info.RecieveIDs = (-oldMailInfo.CreatorID).ToString();
            info.RecieveNames = oldMailInfo.CreatorName;


            mail.Send(info, null, WriteMailMode.New);

            context.Response.Write("ok");
            context.Response.End();


          // info.Content


        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}